package ch.rheintalconnection.sysventory.presentation.panels;

import java.util.ArrayList;
import java.util.List;

import ch.rheintalconnection.sysventory.application.PCAttribute;
import ch.rheintalconnection.sysventory.application.PCDatas;
import ch.rheintalconnection.sysventory.domain.Client;
import ch.rheintalconnection.sysventory.domain.ScanEntry;
import ch.rheintalconnection.sysventory.technicalServices.IDataReader;

import com.vaadin.ui.VerticalLayout;

public class HistoryPanel extends VerticalLayout {

	private static final long serialVersionUID = -170568458710245416L;

	public HistoryPanel(Client client, IDataReader dataReader) {
		//Table table = new Table();
		//table.setSizeFull();
		//this.addComponent(table);

		List<ScanEntry> scanEntries = dataReader.selectScanEntries(client);
		List<PCDatas> pcdatasList = getPCDatas(scanEntries);
		List<PCAttribute> displayAttributes = getDisplayAttributes();
		TablePanel tablePanel = new TablePanel("History", dataReader, false);
		this.addComponent(tablePanel);
		tablePanel.fillTable(displayAttributes, pcdatasList);
	}

	private List<PCDatas> getPCDatas(List<ScanEntry> scanEntries) {
		List<PCDatas> pcdatasList = new ArrayList<PCDatas>();
		for (ScanEntry scanEntry : scanEntries) {
			pcdatasList.add(new PCDatas(scanEntry));
		}
		return pcdatasList;
	}

	private List<PCAttribute> getDisplayAttributes() {

		List<PCAttribute> pcAttributes = new ArrayList<PCAttribute>();
		pcAttributes.add(PCAttribute.ScanDate);
		pcAttributes.add(PCAttribute.Programs);
		pcAttributes.add(PCAttribute.Printers);
		pcAttributes.add(PCAttribute.OSName);
		pcAttributes.add(PCAttribute.OSVersion);
		pcAttributes.add(PCAttribute.OSTechnology);
		pcAttributes.add(PCAttribute.CPUDesc);
		pcAttributes.add(PCAttribute.CPUFamily);
		pcAttributes.add(PCAttribute.CPUCores);
		pcAttributes.add(PCAttribute.CPUClockrate);
		pcAttributes.add(PCAttribute.PCName);
		pcAttributes.add(PCAttribute.PCRAM);
		pcAttributes.add(PCAttribute.PCType);
		pcAttributes.add(PCAttribute.PCHD);
		pcAttributes.add(PCAttribute.NICIP);
		pcAttributes.add(PCAttribute.NICMacAddress);
		pcAttributes.add(PCAttribute.NICDesc);
		pcAttributes.add(PCAttribute.NICGateway);
		pcAttributes.add(PCAttribute.NICDHCP);
		pcAttributes.add(PCAttribute.NICSubnet);

		return pcAttributes;
	}
}
